<script type="text/javascript">
$(document).ready(function(){
	$("#periode").change(function(){
		var periode = $("#periode").val();
		if(periode == 1){
			document.getElementById('tgl1').disabled = false;
			document.getElementById('tgl2').disabled = false;
			document.getElementById('bln1').disabled = false;
			document.getElementById('bln2').disabled = false;
		}
		else if(periode == 2){
			document.getElementById('tgl1').disabled = true;
			document.getElementById('tgl2').disabled = true;
			document.getElementById('bln1').disabled = false;
			document.getElementById('bln2').disabled = false;
		}else{
			document.getElementById('tgl1').disabled = true;
			document.getElementById('tgl2').disabled = true;
			document.getElementById('bln1').disabled = true;
			document.getElementById('bln2').disabled = true;
		}
	});
});
</script>
<?php
	$tgl = date("d");
	$bln = date("m");
	$thn = date("Y");
	
	$periode = $_POST['periode'];
	$tgl1 = $_POST['tgl1'];
	$tgl2 = $_POST['tgl2'];
	$bln1 = $_POST['bln1'];
	$bln2 = $_POST['bln2'];
	$thn1 = $_POST['thn1'];
	$thn2 = $_POST['thn2'];
	$jns = $_POST['jenis'];
	$rs = $_POST['ppk'];
	
	if($rs != ''){
		$id_rs = "and id_ppk = $rs";
	}else{
		$id_rs = "";
	}
?>
<div id="tiga_ba">
	<div id="tiga_baa">Laporan Klaim </div>
	<div id="tiga_bab">
		<!--<a href=""><img src="asset/images/print.png" align="right" width="25"></a>-->
	</div>
	<div class="clear"></div>
</div>

<form method=post action='utama.php?module=mod_laporan&view=klaim'>
	<table style="margin-left: 5px;">
		<tr>
			<td width="75">Periode </td>
			<td width="300">
				<select name="periode" id="periode" class="input1">
					<?php
						if($periode == 1){
							$s1 = "selected";
						}else if($periode == 2){
							$p1 = "disabled";
							$s2 = "selected";
						}else{
							$p1 = "disabled";
							$p2 = "disabled";
							$s3 = "selected";
						}
					?>
					<option value="1" <?php echo $s1; ?>>Hari</option>
					<option value="2" <?php echo $s2; ?>>Bulan</option>
					<option value="3" <?php echo $s3; ?>>Tahun</option>
				</select>
			</td>
			<td width="100"></td>
			<td width="300"></td>
		</tr>
		<tr>
			<td>Dari </td>
			<td>
				<select name="tgl1" id="tgl1" class="input1" <?php echo $p1; ?>>
					<option value="">Tgl</option>
					<?php
						for($i=1;$i<=31;$i++){
							if($i == $tgl && $tgl1 == ''){
								$s = "selected";
							}else if($i == $tgl1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="bln1" id="bln1" class="input1" <?php echo $p2; ?>>
					<option value="">Bln</option>
					<?php
						for($i=1;$i<=12;$i++){
							if($i == $bln && $bln1 == ''){
								$s = "selected";
							}else if($i == $bln1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="thn1" id="thn1" class="input1">
					<option value="">Thn</option>
					<?php
						for($i=2010;$i<=2020;$i++){
							if($i == $thn && $thn1 == ''){
								$s = "selected";
							}else if($i == $thn1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
			</td>
			<td>Jenis</td>
			<td>
				<select name="jenis" id="jenis" class="input2">
					<?php
						if($jns == 'inacbg'){
							$ss = "";
							$si = "selected";
						}else{
							$ss = "selected";
							$si = "";
						}
					?>
					<option value="service" <?php echo $ss; ?>>Fee For Service</option>
					<option value="inacbg" <?php echo $si; ?>>INA-CBG</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Sampai </td>
			<td>
				<select name="tgl2" id="tgl2" class="input1" <?php echo $p1; ?>>
					<option value="">Tgl</option>
					<?php
						for($i=1;$i<=31;$i++){
							if($i == $tgl && $tgl2 == ''){
								$s = "selected";
							}else if($i == $tgl2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="bln2" id="bln2" class="input1" <?php echo $p2; ?>>
					<option value="">Bln</option>
					<?php
						for($i=1;$i<=12;$i++){
							if($i == $bln && $bln2 == ''){
								$s = "selected";
							}else if($i == $bln2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="thn2" id="thn2" class="input1">
					<option value="">Thn</option>
					<?php
						for($i=2010;$i<=2020;$i++){
							if($i == $thn && $thn2 == ''){
								$s = "selected";
							}else if($i == $thn2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
			</td>
			<?php
				if($_SESSION['id_ppk'] == 0){
			?>
			<td>PPK</td>
			<td>
				<select name="ppk" id="ppk" class="input2">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$ppk = mysql_query("select id_ppk,nama from ppk order by nama");
						while($p = mysql_fetch_array($ppk)){
							if($rs == $p['id_ppk']){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$p[id_ppk] $s>$p[nama]</option>";
						}
					?>
				</select>
			</td>
			<?php
				}else{
					$ppk = mysql_query("select id_ppk,nama from ppk where id_ppk = $_SESSION[id_ppk]");
					$p = mysql_fetch_array($ppk);
					echo "<td>PPK</td>
						<td>
							<input type=hidden name=ppk id=ppk class=input2 value=$p[id_ppk]>
							$p[nama]
						</td>";
				}
			?>
		</tr>
		<tr>
			<td></td>
			<td><input name="submit" id="proses" type="submit" class="button" value="Proses" /></td>
			<td></td>
			<td></td>
		</tr>
	</table>
</form>
<?php
	if($periode == 1){
		$tgl1 = "$thn1-$bln1-$tgl1";
		$tgl2 = "$thn2-$bln2-$tgl2";
	}else if($periode == 2){
		$tgl1 = "$thn1-$bln1-01";
		$tgl2 = "$thn2-$bln2-31";
	}else{
		$tgl1 = "$thn1-01-01";
		$tgl2 = "$thn2-12-31";
	}
	
	if($_SESSION['id_jenis_pengguna'] == 5){
		$user = "and id_verifikator = $_SESSION[id_pengguna]";
	}else{
		$user = "";
	}
	if($_POST['submit'] == 'Proses'){
	?>
		<table class="tabel">
			<tr>
				<th rowspan="2" width="30">NO</th>
				<th rowspan="2">Hasil Verifikasi</th>
				<th colspan="2">RJTL</th>
				<th colspan="3">RITL</th>
			</tr>
			<tr>
				<th width="50">Pasien</th>
				<th width="120">Klaim</th>
				<th width="50">Pasien</th>
				<th width="50">LOS</th>
				<th width="120">Klaim</th>
			</tr>
			<?php
				$status = mysql_query("select * from status order by id_status");
				while($s = mysql_fetch_array($status)){
					$no++;
					$klaim_rjtl = mysql_fetch_array(mysql_query("select count(k.id_klaim) as pasien, sum(k.total_diminta) as total from klaim k inner join jenis_layanan j on k.id_jenis_layanan = j.id_jenis_layanan where k.id_status = $s[id_status] and jenis_klaim = '$jns' $id_rs $user and j.kode = 1"));
					$klaim_ritl = mysql_fetch_array(mysql_query("select count(id_klaim) as pasien, sum(total_diminta) as total, sum(datediff(tgl_keluar,tgl_masuk)) as los from klaim k inner join jenis_layanan j on k.id_jenis_layanan = j.id_jenis_layanan where id_status = $s[id_status] $user and jenis_klaim = '$jns' $id_rs and j.kode = 1"));
			?>
					<tr>
						<td align="center">
							<?php echo $no; ?>
						</td>
						<td>
							<?php echo "<a href='module/mod_laporan/detail_klaim.php?id=$s[id_status]&jns=$jns&ppk=$rs' target='_BLANK'>$s[status]</a>";?>
						</td>
						<td align="center">
							<?php echo $klaim_rjtl['pasien']; ?>
						</td>
						<td align="right">
							<?php echo desimal($klaim_rjtl['total']); ?>
						</td>
						<td align="center">
							<?php echo $klaim_ritl['pasien']; ?>
						</td>
						<td align="center">
							<?php echo format_angka($klaim_ritl['los']); ?>
						</td>
						<td align="right">
							<?php echo desimal($klaim_ritl['total']); ?>
						</td>
					</tr>
			<?php
					$total_pasien_rjtl = $total_pasien_rjtl + $klaim_rjtl['pasien'];
					$total_pasien_ritl = $total_pasien_ritl + $klaim_ritl['pasien'];
					$total_klaim_rjtl = $total_klaim_rjtl + $klaim_rjtl['total'];
					$total_klaim_ritl = $total_klaim_ritl + $klaim_ritl['total'];
					$total_los = $total_los + $klaim_ritl['los'];
				}
			?>
			<tr>
				<td colspan="2"><b>Total</b></td>
				<td align="center"><b><?php echo $total_pasien_rjtl; ?></b></td>
				<td align="right"><b><?php echo desimal($total_klaim_rjtl); ?></b></td>
				<td align="center"><b><?php echo $total_pasien_ritl; ?></b></td>
				<td align="center"><b><?php echo $total_los; ?></b></td>
				<td align="right"><b><?php echo desimal($total_klaim_ritl); ?></b></td>
			</tr>
		</table>
	<?php
	}
	?>
